<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">

							<div class="layui-card">
								<div class="layui-card-body">
									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-block">
											<input type="radio" name="status" value="-1" title="拒绝">
											<!--<input type="radio" name="status" value="0" title="待审核">-->
											<input type="radio" name="status" value="1" title="通过" checked="">
										</div>
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">商户：</label>
								<div class="layui-input-block">
									<input type="text" name="sub_shopname" placeholder="请输入商户" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">视频标题：</label>
								<div class="layui-input-block">
									<input type="text" name="title" placeholder="请输入视频标题" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">封面图片：</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn cover"
										id="control_img_button">上传封面</button>
									<button type="button" class="layui-btn layui-btn-danger cover"
										id="control_img_del"
										style="display: {$detail.control_img ? 'inline' : 'none'}">删除封面</button>
									<input type="hidden" id="control_img" value="{$detail.control_img}"
										name="control_img" />
									<input type="hidden" id="temp_url_id" value="" name="temp_url_id" />
								</div>
							</div>
<div class="layui-form-item">
								<label class="layui-form-label"></label>
								<div class="layui-input-block">
									<!-- <video src="{$detail.control_video}" controls="controls" id="control_video_demo"
										style="width: 50%;display: {$detail.control_video ? 'block' : 'none'}">
										您的浏览器不支持 video 标签。
									</video> -->
									<img src="{$detail.control_img}" id="control_img_demo" alt="" style="width: 50%;display: {$detail.control_img ? 'block' : 'none'}">
									<p id="demoText"></p>
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">视频地址：</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn cover"
										id="control_video_button">上传视频</button>
									<button type="button" class="layui-btn layui-btn-danger cover"
										id="control_video_del"
										style="display: {$detail.control_video ? 'inline' : 'none'}">删除视频</button>
									<input type="hidden" id="control_video" value="{$detail.control_video}"
										name="control_video" />
									<input type="hidden" id="temp_url_id" value="" name="temp_url_id" />
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"></label>
								<div class="layui-input-block">
									<video src="{$detail.control_video}" controls="controls" id="control_video_demo"
										style="width: 50%;display: {$detail.control_video ? 'block' : 'none'}">
										您的浏览器不支持 video 标签。
									</video>
									<p id="demoText"></p>
								</div>
							</div>

							<!-- 							<div class="layui-form-item">
								<label class="layui-form-label">视频地址：</label>
								<div class="layui-input-block">
									<input type="text" name="video_url" placeholder="请输入封面图片" autocomplete="off"
										class="layui-input">
								</div>
							</div> -->

							<!-- 							<div class="layui-form-item">
								<label class="layui-form-label">赠送积分：</label>
								<div class="layui-input-block">
									<input type="text" name="give_score" lay-verify="give_score" placeholder="请输入赠送积分"
										autocomplete="off" class="layui-input">
								</div>
							</div> -->
							<div class="layui-form-item">
								<label class="layui-form-label">点击率：</label>
								<div class="layui-input-block">
									<input type="text" name="hits" lay-verify="hits" placeholder="请输入点击率"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">备注：</label>
								<div class="layui-input-block">
									<input type="text" name="remark" placeholder="请输入备注" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">原因：</label>
								<div class="layui-input-block">
									<input type="text" name="cause" placeholder="请输入原因" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<!-- 		<div class="layui-form-item">
								<label class = "layui-form-label">评星等级：</label>
								<div id = "score"></div>
							</div> -->

							<!--<div class="layui-form-item">
								<label class="layui-form-label">是否推荐：</label>
								<div class="layui-input-block">
									<input type="checkbox" name="status" lay-skin="switch" lay-text="推荐|不推荐">
								</div>
							</div>
							-->
							<!-- 		<div class="layui-form-item">
								<label class="layui-form-label">服务类型：</label>
								<div class="layui-input-block service_type"></div>
							</div> -->

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'rate', 'upload'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form,
					upload = layui.upload;
				var rate = layui.rate;
				//渲染
				var ins1 = rate.render({
					elem: '#score', //绑定元素
					half: true,
					value: _data.score,
					choose: function(value) {
						_data.score = value;
					}
				});

				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					var lock = false
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							if (_data.id) {
								submitdata(server.sys_shop_video_update);
							}
							// else {
							// 	delete _data.id;
							// 	submitdata(server.master_insert);
							// }
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				};
				initdata();


				var uploadInst = upload.render({
					elem: '#control_video_button', //绑定元素
					url: server.upimg, //上传接口
					accept: 'video',
					before: function(obj) {
						console.log(obj);
						//预读本地文件示例，不支持ie8
						obj.preview(function(index, file, result) {
							console.log(result);
							$('#control_video_demo').attr('src', result); //图片链接（base64）
							$('#control_video_demo').css('display', 'block');
							$('#control_video_del').css('display', 'inline');
						});
					},
					done: function(res) {
						console.log(res);

						//如果上传失败
						if (res.code != 1) {
							return layer.msg('上传失败');
						}
						//上传成功
						document.getElementById("control_video").value = res.filename;
						document.getElementById("temp_url_id").value = res.msg;

					},
					error: function(res) {
						console.log(res);
						//演示失败状态，并实现重传
						var demoText = $('#demoText');
						demoText.html(
							'<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>'
						);
						demoText.find('.demo-reload').on('click', function() {
							uploadInst.upload();
						});
					}
				});

				$('#control_video_del').click(function() {
					$('#control_video_demo').css('display', 'none');
					$('#control_video_del').css('display', 'none');
					$('#control_video').val('');
				})

				var uploadInst_img = upload.render({
					elem: '#control_img_button', //绑定元素
					url: server.upimg, //上传接口
					accept: 'img',
					before: function(obj) {
						console.log(obj);
						//预读本地文件示例，不支持ie8
						obj.preview(function(index, file, result) {
							console.log(result);
							$('#control_img_demo').attr('src', result); //图片链接（base64）
							$('#control_img_demo').css('display', 'block');
							$('#control_img_del').css('display', 'inline');
						});
					},
					done: function(res) {
						console.log(res);
				
						//如果上传失败
						if (res.code != 1) {
							return layer.msg('上传失败');
						}
						//上传成功
						document.getElementById("control_img").value = res.filename;
						document.getElementById("temp_url_id").value = res.msg;
				
					},
					error: function(res) {
						console.log(res);
						//演示失败状态，并实现重传
						var demoText = $('#demoText');
						demoText.html(
							'<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>'
						);
						demoText.find('.demo-reload').on('click', function() {
							uploadInst.upload();
						});
					}
				});
				
				$('#control_img_del').click(function() {
					$('#control_img_demo').css('display', 'none');
					$('#control_img_del').css('display', 'none');
					$('#control_img').val('');
				})
				
				function initdata() {
					$.get(server.sys_shop_video_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {

								var data = res.shop_video

								// document.getElementById("control_video").value = data.data.video_url;
								$('#control_video_demo').attr('src', data.data.video_url); //图片链接（base64）
								$('#control_img_demo').attr('src', data.data.video_pic); //图片链接（base64）
								form.val("test_detail", data.data);
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
			});
		</script>
	</body>

</html>